/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package BLL;

import DAL.MyConnectUnit;
import DTO.Fine;
import java.sql.ResultSet;
import java.util.HashMap;
import java.util.HashSet;

/**
 *
 * @author Quan_Nuce
 */
public class BFine {
    MyConnectUnit connect;
     public BFine() {
        this.connect = DAL.DAL.getDAL();
}
             public HashSet<Fine>getFines(String condition, String OderBy) throws Exception{
        ResultSet result = this.connect.Select("Fine",condition,OderBy);
        HashSet<Fine> fines = new HashSet<Fine>();
        while(result.next()){
            Fine fine = new Fine();
            fine.setFineID(result.getInt("FineID"));
            fine.setFineRate(result.getFloat("FineRate"));
          fine.setDescription(result.getString("Description"));
            
            
            fines.add(fine);
        }
        return fines;
    }
             
                     public HashSet<Fine>getFines(String condition) throws Exception{
        return getFines(condition,null);
    }
  public HashSet<Fine>getFines() throws Exception{
        return getFines(null);
    }
       public Fine getByID(int id)throws Exception{
        HashSet<Fine>fines = this.getFines("FineID = "+ id);
        if(fines.size()>0)
            return fines.toArray(new Fine[fines.size()])[0];
        return null;
       
   }
              public void Insert(Fine fine)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("FineID", fine.getFineID());
        map.put("FineRate", fine.getFineRate());
        map.put("Description", fine.getDescription());
        
        this.connect.Insert("Fine", map);
       
   }
                     public void Inserts(HashSet<Fine> fines)throws Exception{
        for(Fine fine:fines)
            this.Insert(fine);
       
   
}
              public void Update(Fine fine)throws Exception{
        HashMap<String, Object>map = new HashMap<String,Object>();
        map.put("FineRate", fine.getFineRate());
        map.put("Description", fine.getDescription());
       
        this.connect.Update("Fine", map,"FineID="+fine.getFineID());
       
   }
           public void Updates(HashSet<Fine> fines)throws Exception{
        for(Fine fine:fines)
            this.Update(fine);
}
                 public void Delete(Fine fine) throws Exception{
        this.connect.Delete("Fine", "FineID="+fine.getFineID());
    }
       public void Deletes(HashSet<Fine> fines) throws Exception {
        for(Fine fine:fines)
            this.Delete(fine);
   }        
    
}